<?php
/* [$WindsForce] (C)Hunzhiwange.COM Since 2012.03.17.
   广告位&数据位控制器($$)*/

!defined('Q_PATH') && exit;

class AdpositionController extends AController{

	public function init__(){
		parent::init__();

		if($GLOBALS['___login___']['user_id']!=1){
			$this->E(Q::L('只有用户ID为1的超级管理员才能够访问本页','Controller'));
		}
	}
	
	public function filter_(&$arrMap){
		$arrMap['A.adposition_name']=array('like',"%".Q::G('adposition_name')."%");
		$arrMap['A.adposition_code']=array('like',"%".Q::G('adposition_code')."%");

		// 数据位
		$nIsData=Q::G('adposition_isdata');
		if($nIsData!==null && $nIsData!=''){
			$arrMap['A.adposition_isdata']=$nIsData;
		}
		
		// 广告位类型
		$sType=Q::G('adposition_type');
		if($sType!==null && $sType!=''){
			$arrMap['A.adposition_type']=$sType;
		}
		
		// 添加时间
		$this->getTime_('A.create_dateline',$arrMap);
	}

	public function bAdd_(){
		Core_Extend::loadCache('app');
		$this->assign('arrApps',$GLOBALS['_cache_']['app']);
	}

	public function bEdit_(){
		$this->bAdd_();
	}

	public function bIndex_(){
		$this->bAdd_();
	}

	public function check_code(){
		$sAdpositionCode=trim(Q::G('adposition_code'));
		$nId=intval(Q::G('id'));

		if(!$sAdpositionCode){
			exit('false');
		}

		// 查询条件
		$arrWhere=array();
		$arrWhere['adposition_code']=$sAdpositionCode;
		if($nId){
			$arrWhere['adposition_id']=array('neq',$nId);
		}

		$oAdposition=AdpositionModel::F()->where($arrWhere)->setColumns('adposition_id')->getOne();
		if(empty($oAdposition['adposition_id'])){
			exit('true');
		}else{
			exit('false');
		}
	}

	public function getType($sType){
		switch($sType){
			case 'image':
				return '图片';
				break;
			case 'code':
				return '代码';
				break;
			case 'text':
				return '文字';
				break;
			case 'flash':
				return '动画';
				break;
		}
	}

	public function getDataType($nType){
		switch($nType){
			case 1:
				return '<span style="color:#ED145B;">数据位</span>';
				break;
			default:
				return '<span style="color:#0DD07F;">广告位</span>';
				break;
		}
	}

}
